<template>
  <view class="viewport">
   

    <view class="logo">
    
      <!-- <image
       src="/static/yuesao.png"
      ></image> -->
      
    </view>
    <view class="login">
      <!-- 网页端表单登录 -->
     
      <input class="input" type="text" v-model="user_info.userid" placeholder="请输入用户名/手机号码" />
      <input class="input" type="text" v-model="user_info.password" password placeholder="请输入密码" />
      <view style="display: flex;">
        
      <input  class="input2" type="text" v-model="user_info.code" placeholder="请输入验证码" />
      <view></view>
      <img
        :src="code_imgs"
      alt=""
        style="width: 200rpx;height: 100rpx;padding-left: 20rpx;"
        @click="Getcodeimg"
      />
      </view>
      
      <button class="button phone" @click="Register" >注册</button>
      <view class="extra">
        <view class="caption">
          <text>其他注册方式</text>
        </view>
      </view>
      <view class="tips">登录/注册即视为你同意<a href="">《服务条款》</a></view>
    </view>

  </view>
</template>

<script setup lang="ts" >
import {useMemberStore} from "@/stores/modules/member.ts"
import {http} from '@/utlis/http'
import {ref} from 'vue'
const user_info=ref({
  userid:'',
  password:'',
  code:''
})
const GetUuid=()=>{
  let str='xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
  return str.replace(/[x]/g,item=>{
    const r =Math.random()*0x10 | 0
    const v=item==='x' ? r :(r&0x3 | 0x8)
    return v.toString(0x10)
  })
}


const uuid=ref('')
const code_imgs=ref('')
const Getcodeimg=()=>{
uuid.value=GetUuid()
code_imgs.value='https://www.damer.asia/api/image_codes/'+uuid.value+'/'
}
Getcodeimg()
const head=ref('')
const apis=()=>{
	return http({
		method:'GET',
		url:'userinfo/'
	})
}
const Register=async ()=>{
uni.request({
  url: 'register/',
  data: {
    userid:user_info.value.userid,
    password:user_info.value.password,
    code:user_info.value.code,
    uuid:uuid.value
  },
  
  method: 'post',
  sslVerify: true,
  success: ({ data, statusCode, header }) => {
    console.log('data:',data)
      if(data.code == 0 || data.code==200){
        uni.showToast({
          title: data.errmsg,
          icon: 'success',
          mask: true
        })
       // #ifdef MP-WEIXIN || H5
       var tm_str=String(header['Set-Cookie']).replace(/,/g,';')
      var cookieareey=tm_str.split(';')
      var cookies={}
      for(var i=0;i<cookieareey.length;i++){
        var cookie=cookieareey[i].split('=')
        var key=cookie[0]
        var value=cookie[1]
        cookies[key]=value
      }
      var username=cookies['username']
      var sessionid=cookies['sessionid']
      const memberStore = useMemberStore()
  memberStore.setProfile('username='+username+';sessionid='+sessionid
  )
      // #endif
    
      // apis()
      uni.switchTab({ url: '/pages/my/my' })
      }
      else{
        uni.showToast({
          title: data.errmsg,
          icon: 'error',
          mask: true
        })
      }
  },
  fail: (error) => {}
})
}
     





</script>

<style lang="scss">
page {
  height: 100%;
}

.viewport {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 20rpx 40rpx;
}

.logo {
  flex: 1;
  text-align: center;
  image {
    width: 240*2rpx;
    height: 240rpx;
    margin-top: 15vh;
  }
}

.login {
  display: flex;
  flex-direction: column;
  height: 60vh;
  padding: 40rpx 20rpx 20rpx;

  .input {
    width: 100%;
    height: 80rpx;
    font-size: 28rpx;
    border-radius: 72rpx;
    border: 1px solid #ddd;
    padding-left: 30rpx;
    margin-bottom: 20rpx;
  }
  .input2 {
    width: 64%;
    height: 80rpx;
    font-size: 28rpx;
    border-radius: 72rpx;
    border: 1px solid #ddd;
    padding-left: 30rpx;
    margin-bottom: 20rpx;
  }

  .button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 80rpx;
    font-size: 28rpx;
    border-radius: 72rpx;
    margin-top: 10rpx;
    color: #fff;
    .icon {
      font-size: 40rpx;
      margin-right: 6rpx;
    }
  }

  .phone {
    background-color: #28bb9c;
  }

  .wechat {
    background-color: #06c05f;
  }

  .extra {
    flex: 1;
    padding: 70rpx 70rpx 0;
    .caption {
      width: 440rpx;
      line-height: 1;
      border-top: 1rpx solid #ddd;
      font-size: 26rpx;
      color: #999;
      position: relative;
      text {
        transform: translate(-40%);
        background-color: #fff;
        position: absolute;
        top: -12rpx;
        left: 50%;
      }
    }

    .options {
      display: flex;
      justify-content: center;
      align-items: center;
      margin-top: 70rpx;
      button {
        padding: 0;
        background-color: transparent;
        &::after {
          border: none;
        }
      }
    }

    .icon {
      font-size: 24rpx;
      color: #444;
      display: flex;
      flex-direction: column;
      align-items: center;

      &::before {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 80rpx;
        height: 80rpx;
        margin-bottom: 6rpx;
        font-size: 40rpx;
        border: 1rpx solid #444;
        border-radius: 50%;
      }
    }
    .icon-weixin::before {
      border-color: #06c05f;
      color: #06c05f;
    }
  }
}

.tips {
  position: absolute;
  bottom: 80rpx;
  left: 20rpx;
  right: 20rpx;
  font-size: 22rpx;
  color: #999;
  text-align: center;
}
</style>